package com.itheima.reggie.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.reggie.pojo.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

public interface UserDao extends BaseMapper<User> {
    /**
     * 通过手机号查询用户
     */
    @Select("select * from user where phone=#{phone}")
    User findUserByPhone(String phone);

    /**
     * 新增用户
     * 1. 插入用户信息：只填充2个字段：phone, status
     * 2. 获取新增用户的id
     * 3. 方法名不能叫：save() 因为会激活aop填充公共字段
     */
    @Insert("insert into user (phone, status) values (#{phone},#{status})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void add(User user);

    @Select("select * from user where id=#{userId}")
    User findById(Long userId);
}
